/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package timer;
import java.util.Timer;
import java.util.TimerTask;

/**
 *
 * @author Welington
 */

public class TimeController {
    private static TimeController controller = null;
    private Timer timer;
    
    public static TimeController getInstance() {
        if (controller == null)
            controller = new TimeController();
        
        return controller;
    }
    
    private TimeController() {
        timer = new Timer(true);
    }
    
    public void register(final ITimerTask task, final long period) {
        TimerTask tt = new TimerTask() {
            @Override
            public void run() {
                task.onTimeout();
            }
        };
        
        timer.scheduleAtFixedRate(tt, period, period);
    }
    
    public void unregisterAll() {
        timer.cancel();
    }
}